import 'package:flutter/material.dart';

enum HVVNZZButtonAxis { horizontal, vertical }

class ZZButton extends StatefulWidget {
  final Widget? title;
  final Widget? image;
  final Widget? selImage;
  final double? width;
  final double? height;
  final GestureTapCallback? onTap;
  final MainAxisAlignment mainAxisAlignment;
  final CrossAxisAlignment crossAxisAlignment;

  final HVVNZZButtonAxis axis;

  final bool isSelected;
  final bool enable;
  final double space;

  final EdgeInsetsGeometry? padding;
  final EdgeInsetsGeometry? margin;

  final Decoration? decoration;

  final BoxConstraints? constraints;

  const ZZButton(
      {this.isSelected = false,
      this.enable = true,
      this.axis = HVVNZZButtonAxis.horizontal,
      this.mainAxisAlignment = MainAxisAlignment.start,
      this.crossAxisAlignment = CrossAxisAlignment.center,
      this.padding,
      this.margin,
      this.space = 0,
      this.decoration,
      this.title,
      this.image,
      this.selImage,
      this.width,
      this.height,
      this.onTap,
      this.constraints,
      super.key});

  @override
  State<ZZButton> createState() => _ZZButtonState();
}

class _ZZButtonState extends State<ZZButton> {
  Widget? _showImage() {
    Widget? showImg =
        widget.isSelected ? (widget.selImage ?? widget.image) : widget.image;

    return showImg;
  }

  @override
  Widget build(BuildContext context) {
    Widget? showImg = _showImage();
    List<Widget> children = [
      showImg ?? Container(),
      widget.axis == HVVNZZButtonAxis.horizontal
          ? SizedBox(
              width: showImg == null || widget.title == null ? 0 : widget.space)
          : SizedBox(
              height:
                  showImg == null || widget.title == null ? 0 : widget.space),
      widget.title ?? Container()
    ];
    return IgnorePointer(
      ignoring: !widget.enable,
      child: GestureDetector(
        onTap: widget.onTap,
        child: Container(
          constraints: widget.constraints,
          width: widget.width,
          height: widget.height,
          padding: widget.padding,
          margin: widget.margin,
          decoration: widget.decoration,
          child: widget.axis == HVVNZZButtonAxis.horizontal
              ? Row(
                  mainAxisAlignment: widget.mainAxisAlignment,
                  crossAxisAlignment: widget.crossAxisAlignment,
                  children: children,
                )
              : Column(
                  mainAxisAlignment: widget.mainAxisAlignment,
                  crossAxisAlignment: widget.crossAxisAlignment,
                  children: children,
                ),
        ),
      ),
    );
  }
}
